package com.coin900.coin.cmd.coin_order;

import com.coin900.coin.cmd.ACmd;
import com.coin900.coin.cmd.CmdSign;
import com.coin900.coin.code.CmdCode;
import com.coin900.coin.persist.coin.CoinOrderVO;
import com.coin900.coin.service.coin.ICoinOrderService;
import com.google.gson.Gson;
import com.value.mybatis.Pagination;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 订单列表分页显示
 *
 * @author shui
 * @create 2018-01-15
 **/
@Controller
public class CoinOrderListCmd extends ACmd {
    @Override
    public CmdSign execute(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        HashMap<String, Object> signParams = sign.getParams();
        Pagination pagination = respSign.buildPage();
        Map<String,Object> params = pagination.getParams();
        String keyword = (String) signParams.get("keyword");
        if (keyword != null) {
            params.put("keyword", keyword);
        }
        params.put("dataStatus",1);
        List<CoinOrderVO> coinOrderVOS = this.orderService.loadCoinOrderForPage(pagination);
        Gson gson = new Gson();
        String source = gson.toJson(coinOrderVOS);
        respSign.setSource(source);
        respSign.setPageInfo(pagination);
        return respSign;
    }

    @Autowired
    private ICoinOrderService orderService;

    @Override
    public String getCmdCode() {
        return CmdCode.COIN_ORDER_LIST;
    }
}
